//
//  GLLiveHostHeaderView.swift
//  GLUZSwift
//
//  Created by yu on 2025/3/27.
//

import Foundation


class GLLiveHostHeaderView: ZegoLiveHostHeaderView {
    
    lazy var backgroundView: UIView = {
        let bgView = UIView()
        bgView.backgroundColor = UIColor.colorWithHexString("#1E2740", alpha: 0.4)
        bgView.layer.masksToBounds = true
        return bgView
    }()
    
    /// 头像
    lazy var avatarIV: UIImageView = {
        let imageView = UIImageView()
        imageView.layer.masksToBounds = true
        imageView.layer.borderWidth = 1
        imageView.layer.borderColor = UIColor.white.cgColor
        return imageView
    }()
    
    /// 国旗
    lazy var nationalFlagIV: UIImageView = {
        let imageView = UIImageView()
        imageView.layer.cornerRadius = 2
        imageView.layer.borderWidth = 1
        imageView.layer.borderColor = UIColor.white.cgColor
        imageView.layer.masksToBounds = true
        return imageView
    }()
    
    /// 评分
    lazy var starView: RatingStar = {
        let rsV = RatingStar()
        rsV.isEnable = false
        rsV.style = .full
        rsV.backgroundColor = .clear
        rsV.imageLight = UIImage(named: "翻译星星实心")!
        rsV.imageDark = UIImage(named: "翻译星星空心")!
        
        return rsV
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .clear
        headLabel.removeFromSuperview()
        headNameLabel.font = UIFont.systemFont(ofSize: 15)
        insertSubview(backgroundView, at: 0)
        addSubview(avatarIV)
        addSubview(nationalFlagIV)
        addSubview(starView)
    }
    
    override func setupLayout() {
        
        self.backgroundView.frame = self.bounds
        self.backgroundView.layer.cornerRadius = self.bounds.height / 2
        
        let space: CGFloat = 5
        
        self.avatarIV.frame = CGRectMake(0, 0, self.bounds.height, self.bounds.height)
        self.avatarIV.layer.cornerRadius = self.avatarIV.height / 2
        
        let nationalFlagSize = CGSizeMake(self.avatarIV.bounds.width * 4 / 7, self.avatarIV.bounds.width * 2 / 7)
        self.nationalFlagIV.frame = CGRectMake( self.avatarIV.bounds.width / 2 - nationalFlagSize.width / 2, self.avatarIV.bounds.height - nationalFlagSize.height / 2, nationalFlagSize.width, nationalFlagSize.height )
        
//        self.headNameLabel.sizeToFit()
//        let nameSize = CGSizeMake(ceil(self.headNameLabel.bounds.size.width), ceil(self.headNameLabel.bounds.size.height))
        self.headNameLabel.frame = CGRectMake(self.avatarIV.frame.maxX + space, self.bounds.height / 2 - 3 - 18, self.bounds.width - 20 - self.avatarIV.frame.maxX + space , 18)
        
        self.starView.frame = CGRectMake(self.headNameLabel.frame.minX, self.bounds.height / 2 + 3, self.headNameLabel.bounds.width, 20)
    }
    
    @MainActor required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
